package com.itheima.aop;

import com.itheima.constant.MessageConstant;
import com.itheima.exe.BusinessRuntimeException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class myAop {

    @Around("com.itheima.aop.asp.add()")
    public Object add(ProceedingJoinPoint joinPoint){

        Object proceed = null;
        try {
            proceed = joinPoint.proceed(joinPoint.getArgs());
        } catch (Throwable throwable) {
            throw  new BusinessRuntimeException(MessageConstant.ADD_CHECKITEM_FAIL);
        }

        return proceed;
    }
    @Around("com.itheima.aop.asp.delete()")
    public Object delete(ProceedingJoinPoint joinPoint){

        Object proceed = null;
        try {
            proceed = joinPoint.proceed(joinPoint.getArgs());
        } catch (Throwable throwable) {
            throw  new BusinessRuntimeException(MessageConstant.DELETE_CHECKITEM_FAIL);
        }

        return proceed;
    }
    @Around("com.itheima.aop.asp.edit()")
    public Object edit(ProceedingJoinPoint joinPoint){

        Object proceed = null;
        try {
            proceed = joinPoint.proceed(joinPoint.getArgs());
        } catch (Throwable throwable) {
            throw  new BusinessRuntimeException(MessageConstant.EDIT_CHECKITEM_FAIL);
        }

        return proceed;
    }
    @Around("com.itheima.aop.asp.findPage()")
    public Object findPage(ProceedingJoinPoint joinPoint){
        Object proceed = null;
        try {
            proceed = joinPoint.proceed(joinPoint.getArgs());
        } catch (Throwable throwable) {
            throw  new BusinessRuntimeException(MessageConstant.QUERY_CHECKITEM_FAIL);
        }

        return proceed;
    }

}
